package com.test.wog.controller;

import com.test.wog.service.NodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *关键节点的Controller层
 *
 * @author linxun@buaa.edu.cn
 * @since 2020-01-26
 */
@Api(value = "关键节点Controller", tags = {"关键节点操作接口"})
@RestController
public class NodeController {
    @Autowired
    private NodeService ns;

    @ApiOperation(value = "关键节点查询", notes="支持关键节点的查询操作，不传入参数则返回所有关键节点")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "关键点名称，非空时返回名称为name的点", required = false, paramType = "query", defaultValue = "延庆汽车站"),
            @ApiImplicitParam(name = "type", value = "类型名称，非空时返回名称为name的点", required = false, paramType = "query", defaultValue = "airport"),
            @ApiImplicitParam(name = "lon", value = "关键点经度，非空时返回最近的点", required = false, paramType = "query", defaultValue = "115.985279"),
            @ApiImplicitParam(name = "lat", value = "关键点纬度，非空时返回最近的name的点", required = false, paramType = "query", defaultValue = "40.46178")
    })
    @RequestMapping(value = "/getNode", method = RequestMethod.GET)
    @ResponseBody
    public String getNode(//根据特定输入筛选关键点
        @RequestParam(value = "name",required = false) String name,
        @RequestParam(value = "type",required = false) String type,
        @RequestParam(value = "lon",required = false) Double lon,
        @RequestParam(value = "lat",required = false) Double lat
    ){
        String result = "[]";

        if(name == null){
            if(type == null){
                if(lon == null && lat == null){
                    return ns.getAllNode();
                }
                return ns.getNodeByLoc(lon, lat);
            }
            return ns.getNodeByType(type);
        }
        return ns.getNodeByName(name);
    }

//    /**
//     * Get node by loc int.
//     *
//     * @return the int
//     */
//    @RequestMapping("/init")
//    @ResponseBody
//    public int insertNode(
//    ){
//        return ns.insertNode();
//    }
}
